﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XLua;

namespace ABFramework
{
    /// <summary>
    /// 项目路径类
    /// </summary>
    public class PathTools
    {
        /// <summary>
        /// 需要打包的资源的根目录名字
        /// 放在Editor下是为了打包时,资源不会被打进包体中
        /// 所有的包中资源以AB形式保存
        /// </summary>
        public const string NEED_PACKED_PATH = "Module/Editor";

        /// <summary>
        /// 需要打包的场景的目录（也可将场景放在模块的直接子文件夹中）
        /// </summary>
        public const string NEED_PACKED_SCENES = "Scenes";

        /// <summary>
        /// 构建的AssetBundle资源包输出目录
        /// </summary>
        public const string BUILD_AB_OUT_PATH = "HotUpdateOut";

        /// <summary>
        /// 热更资源版本配置文件
        /// </summary>
        public const string UPDATE_VERSION_CONFIG = "VersionConfig.json";

        /// <summary>
        /// 公告信息
        /// </summary>
        public const string NOTICE_CONFIG = "Notice.json";

        /// <summary>
        /// 项目描述文件
        /// </summary>
        public const string PROJECT_DESCRIPTION = "Resources/Description/Description.txt";

        /// <summary>
        /// 存放项目所有的lua代码根目录
        /// </summary>
        public const string LUA_ROOT_PATH = "Scripts/Lua/src";

        /// <summary>
        /// 拷贝lua到输出目录的目录名
        /// </summary>
        public const string LUA_DESTION_PATH = "luascripts";

        /// <summary>
        /// 游戏日志信息
        /// </summary>
        public const string DEBUG_LOG_NAME = "Log.txt";

        /// <summary>
        /// 校验文件名字
        /// </summary>
        public const string VERYIFY_FILE_NAME = "VerifyFiles.txt";

        /// Android iOS Windows 描述文字（这3个常量不要动）
        public const string DESC_ANDROID = "Android";
        public const string DESC_IOS = "iOS";
        public const string DESC_WINDOWS = "Windows";

        /// <summary>
        /// 获取运行时的平台名称
        /// </summary>
        /// <returns></returns>
        public static string GetRuntimePlatformName()
        {
            string path = string.Empty;
            switch (Application.platform)
            {
                case RuntimePlatform.IPhonePlayer: path = DESC_IOS; break;
                case RuntimePlatform.Android: path = DESC_ANDROID; break;
                case RuntimePlatform.WindowsPlayer:
                case RuntimePlatform.WindowsEditor: path = DESC_WINDOWS; break;
            }

            return path;
        }

        /// <summary>
        /// 获取WWW协议下载（AB包）路径
        /// </summary>
        /// <returns></returns>
        public static string GetWWWPath()
        {
            //返回路径字符串
            string strReturnWWWPath = string.Empty;

            switch (Application.platform)
            {
                //Windows 主平台
                case RuntimePlatform.WindowsPlayer:
                case RuntimePlatform.WindowsEditor:
                    strReturnWWWPath =/* "file://" +*/ GetPlatformABRootPath();
                    break;
                //Android 平台
                case RuntimePlatform.Android:
                    strReturnWWWPath = "jar:file://" + GetPlatformABRootPath();
                    break;
                //IPhone平台
                case RuntimePlatform.IPhonePlayer:
                    strReturnWWWPath = GetPlatformABRootPath() + "/Raw/";
                    break;
                default:
                    break;
            }

            return strReturnWWWPath;
        }

        /// <summary>
        /// 获取AB资源的当前平台的根路径
        /// 算法：
        ///     1： 平台(PC/移动端)路径。
        ///     2： 平台的名称
        /// </summary>
        public static string GetPlatformABRootPath()
        {
            string path = GetABRootPath() + "/" + GetRuntimePlatformName();
            return path.Replace("\\", "/");
        }

        /// <summary>
        /// 获取平台的路径
        /// </summary>
        /// <returns></returns>
        public static string GetABRootPath()
        {
            string strReturnPlatformPath = string.Empty;
            switch (Application.platform)
            {
                case RuntimePlatform.WindowsPlayer:
                case RuntimePlatform.WindowsEditor:
                    strReturnPlatformPath = Application.streamingAssetsPath;
                    break;
                case RuntimePlatform.IPhonePlayer:
                case RuntimePlatform.Android:
                    strReturnPlatformPath = Application.persistentDataPath;
                    break;
                default:
                    break;
            }
            return strReturnPlatformPath;
            //return Application.persistentDataPath;
        }

    }
}

